/*************************************************************************
	> File Name: 1.hzoj245.cpp
	> Author: 
	> Mail: 
	> Created Time: 日  6/ 6 14:09:33 2021
 ************************************************************************/

#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int n;
    vector<int> arr;
    cin >> n;
    for (int i = 0, a; i < n; i++) {
        cin >> a;
        arr.push_back(a);
    }
    sort(arr.begin(), arr.end());
    int p = arr[n / 2];
    int sum = 0;
    for (int i = 0; i < n; i++) sum += abs(arr[i] - p);
    cout << sum << endl;
    return 0;
}
